<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Leo108\Cas\Contracts\Models\UserModel;

class User extends Authenticatable implements UserModel
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


     /**
     * 获取用户名
     * 需要保证用户名在 Cas 系统中的唯一性，
     * 我们在 Cas Client 通过它的值来唯一确定用户
     *
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * 获取用户属性
     *
     * @return array
     */
    public function getCASAttributes(): array
    {
        return $this->attributesToArray();
    }

    /**
     * 获取用户模型实例
     *
     * @return Model
     */
    public function getEloquentModel(): Model
    {
        return $this;
    }
}
